﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SSharp.Core.Evaluator {
    public static partial class Eval {
        private class BeginEvaluator : SpecialFormEvaluator {
            public BeginEvaluator() : base("begin") { }

			public override EvaluationResult Evaluate(object[] parameters, IEnvironment env) {
				if (parameters.Length == 0)
					return new EvaluationResult(null);

				// evaluate each of the subexpression except the last one
				for (int i = 0; i < parameters.Length - 1; i++) {
					Eval.Evaluate(parameters[i], env);
				}

				// return more evaluation is needed for the last parameter (tail recursion)
				return new MoreEvaluationNeeded(parameters[parameters.Length - 1], env);
            }
        }
    }
}
